package com.sl.au.service.impl;

import java.util.List;

import com.sl.au.entity.AfterSaleActive;
import com.sl.au.entity.NoticeRecord;
import com.sl.au.repository.AfterSaleActiveRepository;
import com.sl.au.repository.NoticeRecordRepository;
import com.sl.au.service.AfterSaleActiveService;
import com.sl.au.service.NoticeRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.sl.au.service.ExcelService;

@Service("noticeRecordService")
@Transactional
public class NoticeRecordServiceImpl extends BaseServiceImpl implements NoticeRecordService {

    @Autowired
    NoticeRecordRepository noticeRecordRepository;

    @Autowired
    ExcelService excelService;


    @Override
    public List<NoticeRecord> getPage(int start, int length, String orderName, String dir) {
        Page<NoticeRecord> pages = null;
        Pageable pageable = new PageRequest(start / length, length, Sort.Direction.DESC, "createTime");
        pages = noticeRecordRepository.findAll(pageable);
        return pages.getContent();
    }

    @Override
    public List<NoticeRecord> getNoticeRecords(int start, int length, String key, String orderName, String dir) {
        Page<NoticeRecord> pages = null;
        Pageable pageable = new PageRequest(start / length, length, Sort.Direction.DESC, "createTime");
        pages = noticeRecordRepository.getName(key, pageable);
        return pages.getContent();
    }
    public NoticeRecordRepository getRepository() {
        return this.noticeRecordRepository;
    }
}
